<?php
$this->pageTitle='Regular Expression Validator';
$this->breadcrumbs=array(
	'Regular Expression Validator',
);
?>
<br>
<h3>Regular Expression Validator</h3>
<p><small>validator a regular expression against input string </small></p>
<br>

<div class="span11">
<?php $form=$this->beginWidget('CActiveForm'); ?>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<div class="span5">
			<strong><?php echo $form->labelEx($model,'Your Regular Expression pattern:'); ?></strong>
			<?php echo CHtml::activeTextArea($model,'input'); ?>
		</div>

		<div class="span5 offset1">
			<strong><?php echo $form->labelEx($model,'Your matching string:'); ?></strong>
			<?php echo CHtml::activeTextArea($model,'input2'); ?>
		</div>
	</div>
 	
	<div class="row submit">
		<div class="span10">
			<?php echo CHtml::submitButton('Encode', array('class'=>'btn btn-danger btn-lg')); ?>
		</div>
	</div>

<?php $this->endWidget(); ?>
	<div class="row">
		<div class="span10">
			<strong><?php echo $form->labelEx($model,'result'); ?></strong>
			<?php echo CHtml::activeTextArea($model,'result'); ?>
		</div>
	</div>
 

</div>

<br>
<br>
<br>
<h3>References Table:</h3>
<br>

<table class="table table-striped"  width="600" border="0" style="table-layout: fixed;">
	<tr>
		<th width="100" scope="col">Character</th>
		<th width="200" scope="col">Legend</th>
		<th width="150" scope="col">Example</th>
		<th width="150" scope="col">Sample Match</th>
	</tr>
	<tr class="blue">
		<td>\d</td>
		<td>One digit</td>
		<td>file_\d\d</td>
		<td>file_25</td>
	</tr>
	<tr class="green">
		<td>\w</td>
		<td>One "word character": letter, underscore or digit</td>
		<td>\w-\w\w\w</td>
		<td>A-b_1</td>
	</tr>
	<tr class="blue">
		<td>\s</td>
		<td>One white space character (e.g.: a tab)</td>
		<td>ab\s\s\sc</td>
		<td>ab&nbsp;&nbsp;&nbsp;&nbsp;c</td>
	</tr>
	<tr class="green">
		<td>\D</td>
		<td>One character that is not a digit</td>
		<td>\D\D\D</td>
		<td>ABC</td>
	</tr>
	<tr class="blue">
		<td>\W</td>
		<td>One character that is not a word character</td>
		<td>\W\W\W\W\W</td>
		<td>*-+=)</td>
	</tr>
	<tr class="green">
		<td>\S</td>
		<td>One character that is not a space</td>
		<td>\S\S\S\S</td>
		<td>Yoyo</td>
	</tr>
</table>
<br />
<table class="table table-striped" width="600" border="0" style="table-layout: fixed;">
	<tr>
		<th width="100" scope="col">Quantifier</th>
		<th width="200" scope="col">Legend</th>
		<th width="150" scope="col">Example</th>
		<th width="150" scope="col">Sample Match</th>
	</tr>
	<tr class="blue">
		<td>+</td>
		<td>One or more</td>
		<td>Version \w-\w+</td>
		<td>Version A-b1_1</td>
	</tr>
	<tr class="pink">
		<td>{3}</td>
		<td>Exactly three times</td>
		<td>\D{3}</td>
		<td>ABC</td>
	</tr>
	<tr class="blue">
		<td>{2,4}</td>
		<td>Two to four times</td>
		<td>\d{2,4}</td>
		<td>156</td>
	</tr>
	<tr class="pink">
		<td>{3,}</td>
		<td>Three or more times</td>
		<td>\w{3,}</td>
		<td>regex_tutorial</td>
	</tr>
	<tr class="blue">
		<td>*</td>
		<td>Zero or more times</td>
		<td>A*B*C*</td>
		<td>AAACC</td>
	</tr>
	<tr class="pink">
		<td>?</td>
		<td>Once or none</td>
		<td>plurals?</td>
		<td>plural</td>
	</tr>
</table>
<br />
<table class="table table-striped" width="600" border="0" style="table-layout: fixed;">
	<tr>
		<th width="100" scope="col">Character</th>
		<th width="200" scope="col">Legend</th>
		<th width="150" scope="col">Example</th>
		<th width="150" scope="col">Sample Match</th>
	</tr>
	<tr class="blue">
		<td><b>.</b></td>
		<td>Any character except new line</td>
		<td>a.c</td>
		<td>abc</td>
	</tr>
	<tr class="green">
		<td><b>.</b></td>
		<td>Any character except new line</td>
		<td>.*</td>
		<td>whatever, man.</td>
	</tr>
	<tr class="blue">
		<td>\<b>.</b></td>
		<td>A period (special character: needs to be escaped by a \)</td>
		<td>a\.c</td>
		<td>a.c</td>
	</tr>
	<tr class="green">
		<td>\</td>
		<td>Escapes a special character</td>
		<td>\.\*\+\?&nbsp;&nbsp;&nbsp;&nbsp;\$\^\/\&#92;</td>
		<td>.*+?&nbsp;&nbsp;&nbsp;&nbsp;$^/&#92;</td>
	</tr>
	<tr class="blue">
		<td>\</td>
		<td>Escapes a special character</td>
		<td>\[\{\(\)\}\]</td>
		<td>[{()}]</td>
	</tr>
</table>
<br />
<table class="table table-striped" width="600" border="0" style="table-layout: fixed;">
	<tr>
		<th width="100" scope="col">Logic</th>
		<th width="200" scope="col">Legend</th>
		<th width="150" scope="col">Example</th>
		<th width="150" scope="col">Sample Match</th>
	</tr>
	<tr class="blue">
		<td>|</td>
		<td>OR operand</td>
		<td>22|33</td>
		<td>33</td>
	</tr>
	<tr class="pink">
		<td>()</td>
		<td>Capturing group</td>
		<td>A(nt|pple)</td>
		<td>Apple (captures "pple")</td>
	</tr>
	<tr class="blue">
		<td>\1</td>
		<td>Contents of Group 1</td>
		<td>r(\w)g\1x</td>
		<td>regex</td>
	</tr>
	<tr class="pink">
		<td>\2</td>
		<td>Contents of Group 2</td>
		<td>(\d\d)\+(\d\d)=\2\+\1</td>
		<td>12+65=65+12</td>
	</tr>
	<tr class="blue">
		<td>(?:</td>
		<td>Non-capturing group</td>
		<td>A(?:nt|pple)</td>
		<td>Apple</td>
	</tr>
</table>
<br />
<table class="table table-striped" width="600" border="0" style="table-layout: fixed;">
	<tr>
		<th width="100" scope="col">Character</th>
		<th width="200" scope="col">Legend</th>
		<th width="150" scope="col">Example</th>
		<th width="150" scope="col">Sample Match</th>
	</tr>
	<tr class="blue">
		<td>\t</td>
		<td>Tab</td>
		<td>T\t\w{2}</td>
		<td>T&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ab</td>
	</tr>
	<tr class="green">
		<td>\r</td>
		<td>Return character</td>
		<td>see below</td>
		<td></td>
	</tr>
	<tr class="blue">
		<td>\n</td>
		<td>New line character</td>
		<td>see below</td>
		<td></td>
	</tr>
	<tr class="green">
		<td>\r\n</td>
		<td>New line in Windows</td>
		<td>AB\r\nCD</td>
		<td>AB<br />CD
		</td>
	</tr>
</table>
<br />
<table class="table table-striped" width="600" border="0" style="table-layout: fixed;">
	<tr>
		<th width="100" scope="col">Quantifier</th>
		<th width="200" scope="col">Legend</th>
		<th width="150" scope="col">Example</th>
		<th width="150" scope="col">Sample Match</th>
	</tr>
	<tr class="blue">
		<td>+</td>
		<td>The + (one or more) is "greedy"</td>
		<td>\d+</td>
		<td>12345</td>
	</tr>
	<tr class="pink">
		<td>?</td>
		<td>Makes quantifiers "lazy"</td>
		<td>\d+?</td>
		<td>1 in <b>1</b>2345
		</td>
	</tr>
	<tr class="blue">
		<td>*</td>
		<td>The * (zero or more) is "greedy"</td>
		<td>A*</td>
		<td>AAA</td>
	</tr>
	<tr class="pink">
		<td>?</td>
		<td>Makes quantifiers "lazy"</td>
		<td>A*?</td>
		<td>empty in AAA</td>
	</tr>
	<tr class="blue">
		<td>{2,4}</td>
		<td>Two to four times, "greedy"</td>
		<td>\w{2,4}</td>
		<td>abcd</td>
	</tr>
	<tr class="pink">
		<td>?</td>
		<td>Makes quantifiers "lazy"</td>
		<td>\w{2,4}?</td>
		<td>ab in <b>ab</b>cd
		</td>
	</tr>
</table>
<br />
<table class="table table-striped" width="600" border="0" style="table-layout: fixed;">
	<tr>
		<th width="100" scope="col">Character</th>
		<th width="200" scope="col">Legend</th>
		<th width="150" scope="col">Example</th>
		<th width="150" scope="col">Sample Match</th>
	</tr>
	<tr class="blue">
		<td>[stuff]</td>
		<td>One of the characters in the brackets</td>
		<td>[AEIOU]</td>
		<td>One uppercase vowel</td>
	</tr>
	<tr class="green">
		<td>-</td>
		<td>Range indicator</td>
		<td>[a-z]</td>
		<td>One lowercase letter</td>
	</tr>
	<tr class="blue">
		<td>[stuff]</td>
		<td>One of the characters in the brackets</td>
		<td>[AB1-5w-z]</td>
		<td>One of either: A,B,1,2,3,4,5,w,x,y,z</td>
	</tr>
	<tr class="green">
		<td>[stuff]</td>
		<td>One of the characters in the brackets</td>
		<td>[A-Z]+</td>
		<td>GREAT</td>
	</tr>
	<tr class="blue">
		<td>[^x]</td>
		<td>One character that is not x</td>
		<td>[^a-z]{3}</td>
		<td>A1!</td>
	</tr>
	<tr class="green">
		<td>[\d\D]</td>
		<td>One character that is a digit or a non-digit</td>
		<td>[\d\D]+</td>
		<td>Any characters, inc-<br />luding new line
		</td>
	</tr>
</table>
<br />
<table class="table table-striped" width="600" border="0" style="table-layout: fixed;">
	<tr>
		<th width="100" scope="col">Anchor</th>
		<th width="200" scope="col">Legend</th>
		<th width="150" scope="col">Example</th>
		<th width="150" scope="col">Sample Match</th>
	</tr>
	<tr class="blue">
		<td>^</td>
		<td>Beginning of line (but means "not" inside [^brackets])</td>
		<td>^abc .*</td>
		<td>abc (line start)</td>
	</tr>
	<tr class="pink">
		<td>$</td>
		<td>End of line</td>
		<td>.*? the end$</td>
		<td>this is the end</td>
	</tr>
	<tr class="blue">
		<td>\A</td>
		<td>Beginning of string</td>
		<td>\Aabc[\d\D]*</td>
		<td>abc (string...<br />...start)
		</td>
	</tr>
	<tr class="pink">
		<td>\Z</td>
		<td>End of string</td>
		<td>[\d\D]*the end\Z</td>
		<td>this is...<br />...the end
		</td>
	</tr>
	<tr class="blue">
		<td>\b</td>
		<td>Word boundary</td>
		<td>Bob.*\bcat\b</td>
		<td>Bob ate the cat</td>
	</tr>
	<tr class="pink">
		<td>\B</td>
		<td>Not a word boundary</td>
		<td>Bob.*\Bcat\B.*</td>
		<td>Bobcats</td>
	</tr>
</table>
<br />
<table class="table table-striped" width="600" border="0" style="table-layout: fixed;">
	<tr>
		<th width="100" scope="col">Character</th>
		<th width="200" scope="col">Legend</th>
		<th width="150" scope="col">Example</th>
		<th width="150" scope="col">Sample Match</th>
	</tr>
	<tr class="blue">
		<td>[:alpha:]</td>
		<td>Letters</td>
		<td>[8[:alpha:]]+</td>
		<td>WellDone88</td>
	</tr>
	<tr class="green">
		<td>[:alnum:]</td>
		<td>Letters and numbers</td>
		<td>[[:alnum:]]{10}</td>
		<td>ABCDE12345</td>
	</tr>
	<tr class="blue">
		<td>[:punct:]</td>
		<td>Punctuation marks</td>
		<td>[[:punct:]]+</td>
		<td>?!.,:;</td>
	</tr>
</table>
<br />
<table class="table table-striped" width="600" border="0" style="table-layout: fixed;">
	<tr>
		<th width="100" scope="col">Modifier</th>
		<th width="200" scope="col">Legend</th>
		<th width="150" scope="col">Example</th>
		<th width="150" scope="col">Sample Match</th>
	</tr>
	<tr class="blue">
		<td>(?i)</td>
		<td>Case-insensitive</td>
		<td>(?i)Monday</td>
		<td>monDAY</td>
	</tr>
	<tr class="pink">
		<td>(?s)</td>
		<td>The dot (.) matches new line characters (\r\n)</td>
		<td>(?s)From A.*to Z</td>
		<td>From A<br />to Z
		</td>
	</tr>
	<tr class="blue">
		<td>(?m)</td>
		<td>Treats the string as multiple lines, so that ^ and $ can
			match in several places</td>
		<td>(?m)1\r\n^2$\r\n^3$</td>
		<td>1<br />2<br />3
		</td>
	</tr>
	<tr class="pink">
		<td>(?x)</td>
		<td>Comment mode (aka whitespace mode)</td>
		<td>(?x) # this is a<br /># comment<br />abc # write on
			multiple<br /># lines<br />[ ]d # spaces must be<br /># in
			brackets
		</td>
		<td>abc d</td>
	</tr>
</table>
<br />
<table class="table table-striped" width="600" border="0" style="table-layout: fixed;">
	<tr>
		<th width="100" scope="col">Lookaround</th>
		<th width="200" scope="col">Legend</th>
		<th width="150" scope="col">Example</th>
		<th width="150" scope="col">Sample Match</th>
	</tr>
	<tr class="blue">
		<td>(?=</td>
		<td>Positive lookahead</td>
		<td>(?=\d{10})\d{5}</td>
		<td>01234 in <b>01234</b>56789
		</td>
	</tr>
	<tr class="green">
		<td>(?&lt;=</td>
		<td>Positive lookbehind</td>
		<td>(?&lt;=\d)cat</td>
		<td>cat in 1<b>cat</b></td>
	</tr>
	<tr class="blue">
		<td>(?!</td>
		<td>Negative lookahead</td>
		<td>(?!theatre)the\w+</td>
		<td>theme</td>
	</tr>
	<tr class="green">
		<td>(?&lt;!</td>
		<td>Negative lookbehind</td>
		<td>\w{3}(?&lt;!mon)ster</td>
		<td>Munster</td>
	</tr>
</table>
